package com.qf.springbootopenapi.config;

import com.qf.springbootopenapi.interceptor.AutoLoginInterceptor;
import com.qf.springbootopenapi.interceptor.LoginStatusInterceptor;
import com.qf.springbootopenapi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;


@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    
    @Qualifier("userBetterServiceImpl")
    @Autowired
    private UserService userService;
    
    /**
     * 添加自定义拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        AutoLoginInterceptor autoLoginInterceptor = new AutoLoginInterceptor();
        autoLoginInterceptor.setUserService(userService);
        
        registry.addInterceptor(autoLoginInterceptor).addPathPatterns("/login.html");
        
        registry.addInterceptor(new LoginStatusInterceptor()).addPathPatterns(Arrays.asList("/view/**","/plateform.html"));
    }
}
